﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectPool : MonoBehaviour
{
    public int poolNum;//对象池对象数量
    public GameObject shellObj;//炮弹物体
    public static GameObject[] objArray;//对象数组
    private void Awake()
    {
        //通过资源加载的方式自动加载预制体
        shellObj = Resources.Load("Ammo/Bullet") as GameObject;
        objArray=new GameObject[poolNum];//给数组开辟内存
        if(shellObj != null)
        {
            for (int i = 0; i < poolNum; i++)
            {
                objArray[i] = Instantiate(shellObj,transform.position,transform.rotation);
                objArray[i].transform.parent = transform;//认爹
                //启动时隐藏弹夹里的炮弹
                objArray[i].GetComponent<MeshRenderer>().enabled=false;
                //关闭刚体开关
                objArray[i].GetComponent<Rigidbody>().isKinematic = true;
                //关闭碰撞网络
                objArray[i].GetComponent<SphereCollider>().enabled = false;
            }
        }
    }
}